<template>
  <el-container>
    <el-aside>
      <div class="logo-box">
        <el-image style="width: 25px; height: 25px" :src="url"></el-image>
        <h2 class="manage-title" v-show="!flag">嗨购管理后台</h2>
      </div>
      <MenuComp :isCollapse="flag" />
    </el-aside>
    <el-container>
      <el-header>
        <el-icon @click="flag = !flag" :size="30">
          <component :is="headerLeft"></component>
        </el-icon>
        <div class="avatar-box">
          <el-space :size="20">
            <span>欢迎您: {{ userInfo && userInfo.adminname }}</span>
            <el-dropdown>
              <el-avatar
                :size="30"
                src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
              />
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="$router.push('/set')"
                    >设置</el-dropdown-item
                  >
                  <el-dropdown-item @click="handleLogout"
                    >退出</el-dropdown-item
                  >
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-space>
        </div>
      </el-header>
      <el-main>
        <BreadcrumbCom></BreadcrumbCom>
        <!--渲染页面-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { Expand, Fold } from '@element-plus/icons-vue'
import MenuComp from '@/components/MenuCom.vue'
import BreadcrumbCom from '@/components/BreadcrumbCom.vue'
import url from '@/assets/logo.jpg'
import { mapMutations, mapState } from 'vuex'
export default {
  data() {
    return {
      url, // 声明图片文件路径
      flag: false //代表是不折叠面板
    }
  },
  methods: {
    ...mapMutations(['updateUserInfo']),
    handleLogout() {
      localStorage.removeItem('token') // 清除本地token值
      this.updateUserInfo({}) // 将vuex的userInfo赋值{}
      this.$router.push('/login')
    }
  },
  components: {
    Expand,
    Fold,
    MenuComp,
    BreadcrumbCom
  },
  computed: {
    ...mapState(['userInfo']),
    headerLeft() {
      return !this.flag ? 'Expand' : 'Fold'
    },
    asideWidth() {
      return !this.flag ? '200px' : '64px'
    }
  }
}
</script>

<style lang="scss" scoped>
.logo-box {
  height: 64px;
  display: flex;
  align-items: center;
  margin-left: 20px;
  .el-image {
    margin-right: 20px;
    img {
      width: 25px !important;
      height: 25px !important;
    }
  }
  .manage-title {
    color: #fff;
    font-size: 16px;
  }
}
.el-container {
  height: 100%;
  background-color: #dfe6e9;
  .el-aside {
    width: v-bind(asideWidth);
    background-color: #2d3436;
    // 设置过渡动画
    transition: 0.25s;
  }
  .el-header {
    background-color: #7f8fa6;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
</style>
